/**
 * \class SlumpGenerator SlumpGenerator.h <Helper/SlumpGenerator.h>
 *
 *
 *  Created on: Nov 14, 2011
 *      Author: calle
 *
 *  \ingroup HelperClasses
 *
 *  \brief SlumpGenerator uses a list
 * 	to randomly choose one in the list.
 *
 * The list can be made in any arbitrary list as long
 * as it uses [] operator to get a item from the list.
 * Per default it uses RandomizeHelper to generate and
 * 0 as min value.
 *
 * @see RandomizeHelper
 *
 * Example usage:
 * \code
 * class ENUM_CLASS {

	public:
	 enum TEST {
		TYPE_ONE,
		TYPE_TWO,
		TYPE_THREE
		};

		TEST operator[] (int val)
		{
			TEST ret = TYPE_ONE;
			switch(val)
			{
				case 2:
					ret = TYPE_TWO;
					break;
				case 3:
					ret = TYPE_THREE;
					break;
				default:
					ret = TYPE_ONE;
					break;
			}

			return ret;
		}


		static std::string toString(TEST val)
		{
			std::string ret;
			switch(val)
			{
			case TYPE_ONE:
				ret = "Type One";
				break;
			case TYPE_TWO:
				ret = "Type Two";
				break;
			case TYPE_THREE:
				ret = "Type Three";

			}

			return ret;
		}

	 };

	void TestSlumpGenerator()
	{
		ENUM_CLASS myClass;
		SlumpGenerator<ENUM_CLASS,3> gen(myClass);

		const ENUM_CLASS::TEST& type = gen.randomizeType<ENUM_CLASS::TEST>();
		std::cout << "Got " << ENUM_CLASS::toString(type) << std::endl;
	}

 * \endcode
 *
 *
 */

#include <cstdlib>
#include <time.h>

#ifndef SLUMPGENERATOR_H_
#define SLUMPGENERATOR_H_

class RandomizeHelper;

template< class T,int max,int min=0,class R=RandomizeHelper >
class SlumpGenerator{

public:

	/**
	 * \brief Default constructor
	 *
	 * Provide the list from which the type is chosen.
	 *
	 * @param list
	 */
	SlumpGenerator(T list):
		m_list(list)
	{


	}

	/**
	 * \brief Choose randomly one of the types from the provided list
	 *
	 *
	 * \tparam Type class which provided from the list
	 * Example of usage:
	 * \code
	 * SlumpGenerator<ENUM_CLASS,3> gen(myClass);
	 * const ENUM_CLASS::TEST& type = gen.randomizeType<ENUM_CLASS::TEST>();
	 * \endcode
	 * @return Choosen type T
	 */

	template <class C>
	const C& randomizeType()
	{
		const C& ret= m_list[m_Randomizer(min,max)];

		return ret;
	}



private:
	R m_Randomizer;
	T m_list;

};


/**
 * \class RandomizeHelper SlumpGenerator.h <Helper/SlumpGenerator.h>
 *
 *
 *  Created on: Nov 14, 2011
 *      Author: calle
 *
 *  \ingroup HelperClasses
 *
 *  \brief RandomizeHelper is a default classs to use toghether
 *  		with SlumpGenerator for randomization
 *
 *  RandomizeHelper can be used toghether with SlumpGenerator to
 *  crate a random number.
 *  @see SlumpGenerator
 */

class RandomizeHelper
{
public:
	/**
	 * \brief Constructor
	 *
	 *  The parameter doSeed is used to tell Randomizer
	 *  to use the current time as a salt.
	 *
	 *  @see SlumpGenerator
	 *
	 * @param doSeed default to true
	 */
	RandomizeHelper(bool doSeed=true)
	{
		if( doSeed )
		{
			srand(static_cast<unsigned int>(time(NULL)));
		}
	};

	/**
	 * \brief randomly selects a value between min and max
	 *
	 *	WTF
	 *
	 * @param min
	 * @param max
	 * @return a randomly selected value between min and max
	 */
	int operator()(int min,int max)
	{
		return rand() % (max+1) + min;
	}
};
#endif /* SLUMPGENERATOR_H_ */
